/*
 * customer.cpp
 *
 *  Created on: Feb 22, 2016
 *      Author: ezhaome
 */
#include "customer.h"
#include "tools.h"
Customer::Customer(string name)
{
	_name = name;
}

void Customer::addRental(Rental rental)
{
	_rentals.push_back(rental);
}

string Customer::getName()
{
	return _name;
}

string Customer::statement()
{
	string result = "Rental record for " + getName() + "\n";
	vector<Rental>::iterator i = _rentals.begin();
	for (i = _rentals.begin(); i != _rentals.end(); i++)
	{
		result += "\t" + i->getMovie().getTitle() + "\t" + NumberToString(i->getCharge()) + "\n";
	}

	result += "Amount owned is " + NumberToString(getTotalCharge()) + "\n";
	result += "You earned " + NumberToString(getTotalFrequentPoints()) + " frequent renter points";
	return result;
}

double Customer::getTotalCharge()
{
	double result = 0;
	vector<Rental>::iterator i = _rentals.begin();
	for (i = _rentals.begin(); i != _rentals.end(); i++)
	{
		result += i->getCharge();
	}
	return result;
}

int Customer::getTotalFrequentPoints()
{
	int result = 0;
	vector<Rental>::iterator i = _rentals.begin();
	for (i = _rentals.begin(); i != _rentals.end(); i++)
	{
		result += i->getFrequentPoints();
	}
	return result;
}

